package com.credit.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.credit.common.ServerResponse;
import com.credit.mapper.messageTypeMapper;
import com.credit.pojo.message;
import com.credit.pojo.messageList;
import com.credit.pojo.messageType;
import com.credit.service.IMessageSerive;
/**
 * 消息模块代码
 * @author Administrator
 *
 */
@CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
@RestController
@Controller
public class MessageController {

	
	@Autowired
	private IMessageSerive messageSerive;
	
	
	
	/**
	 * 显示消息分类
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectMessageType.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectMessageType(int id) {
		
		return messageSerive.selectMessageType(id);
	}
	
	
	/**
	 * 增加消息分类
	 * @param m
	 * @return
	 */
	@RequestMapping(value = "addMessageType.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addtMessageType(messageType m) {
		
		return messageSerive.insertMessageType(m);
	}
	
	
	
	/**
	 * 修改消息分类
	 * @param m
	 * @return
	 */
	@RequestMapping(value = "upMessageType.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse uptMessageType(messageType m) {
		
		return messageSerive.updateMessageType(m);
	}
	
	
	
	/**
	 * 删除消息分类
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delMessageType.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse deltMessageType(int id) {
		
		return messageSerive.deleteMessageType(id);
	}
	
	
	
	
	
	/**
	 * 查看个人发布消息
	 * @param m
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value = "selectMessage.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectMessage(message m,@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
			@RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
		
		return messageSerive.selectMessage(m, pageNum, pageSize);
	}
	
	
	
	
	/**
	 * 发布通知消息
	 * @param m
	 * @param user
	 * @return
	 */
	@RequestMapping(value = "addMessage.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addMessage(message m,String user) {
		
		return messageSerive.insertMessage(m, user);
	}
	
	
	
	/**
	 * 查看消息通知
	 * @param m
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value = "selectMessageList.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectMessageList(messageList m,@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
			@RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
		
		return messageSerive.selectMessageList(m, pageNum, pageSize);
	}
	
	
	
	
	/**
	 * 查看单个消息详细内容
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectOneMessageList.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectOneMessageList(Integer id) {
		
		return messageSerive.selectOneMessageList(id);
	}
	
	
	/**
	 * 批量修改消息为已读
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "upStateMessageList.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upStateMessageList(String id) {
		
		
		return messageSerive.updateMessageList(id);
	}
	
	
	
	
	
	
	
}
